package com.lifesaftypower.product;

import java.io.Serializable;
import java.util.ArrayList;

import org.w3c.dom.CharacterData;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ProductSeries implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final String TAG = "series";
	private String _description;
	private String _model_overview;
	private String _img_url;
	private String _name;
	private String _overview;
	private ArrayList<Product> _products;

	public ProductSeries(Node xmlNode) {
		if (xmlNode.getNodeType() == Node.ELEMENT_NODE) {
			Element _xmlNode = (Element) xmlNode;
			_name = _xmlNode.getAttribute("name");
			_description = _xmlNode.getAttribute("description");

			NodeList overviewNodes = _xmlNode.getElementsByTagName("overview");

			if (overviewNodes != null && overviewNodes.getLength() > 0) {
				NodeList cdNodes = overviewNodes.item(0).getChildNodes();

				for (int i = 0; i < cdNodes.getLength(); i++) {
					if (Node.CDATA_SECTION_NODE == cdNodes.item(i)
							.getNodeType()) {
						_overview = cdNodes.item(i).getNodeValue();
						break;
					}
				}
			}

			NodeList modelOverviewNodes = _xmlNode
					.getElementsByTagName("model_overview");

			if (modelOverviewNodes != null
					&& modelOverviewNodes.getLength() > 0) {
				NodeList cdNodes = modelOverviewNodes.item(0).getChildNodes();

				for (int i = 0; i < cdNodes.getLength(); i++) {
					if (Node.CDATA_SECTION_NODE == cdNodes.item(i)
							.getNodeType()) {
						_model_overview = cdNodes.item(i).getNodeValue();
						break;
					}
				}
			}

			_img_url = _xmlNode.getAttribute("img_url");
			_products = new ArrayList<Product>();

			NodeList seriesNodes = _xmlNode.getElementsByTagName(Product.TAG);
			for (int i = 0; i < seriesNodes.getLength(); i++) {
				_products.add(new Product(seriesNodes.item(i)));
			}
		}
	}

	public ProductSeries(String _name, String _description, String _overview,
			String _img_url) {
		this._name = _name;
		this._description = _description;
		this._overview = _overview;
		this._img_url = _img_url;
	}

	public String get_description() {
		return _description;
	}

	public String get_img_url() {
		return _img_url;
	}

	public String get_name() {
		return _name;
	}

	public String get_overview() {
		return _overview;
	}

	public ArrayList<Product> get_products() {

		return _products;
	}

	@Override
	public String toString() {
		return "ProductSeries [_name=" + _name + ", _description="
				+ _description + ", _overview=" + _overview + ", _img_url="
				+ _img_url + "]";
	}

	public String get_model_overview() {
		return _model_overview;
	}

	public void set_model_overview(String _model_overview) {
		this._model_overview = _model_overview;
	}

}
